/*
 *
num = 1000, name = zhangsan, score = 98.000000
num = 1001, name = lisi, score = 90.000000
num = 1001, name = lisi, score = 0.000000
num = 1001, name = , score = 99.000000
num = 1002, name = lihua, score = 89.000000
num = 1007, name = wangwu, score = 70.000000

 *
 */
#include<stdio.h>
#include<string.h>
struct student
{
	//学号
	int num;
	//姓名
	char name[16];
	//成绩
	float score;
}stu5={1002,"lihua",89},stu6;

int main(int argc, const char *argv[]){
	//1. 定义完结构体变量再赋值
	struct student stu1;
	stu1.num = 1000;
	strcpy(stu1.name, "zhangsan");
	//此时会抛错，除非是在定义时就赋初值，不然要给字符数组
	//stu1.name = "zhangsan";
	stu1.score = 98;
	printf("num = %d, name = %s, score = %f\n", stu1.num, stu1.name, stu1.score);

	//2. 定义结构体变量时赋初值
	struct student stu2 = {1001, "lisi", 90};
	printf("num = %d, name = %s, score = %f\n", stu2.num, stu2.name, stu2.score);

	//2.1 定义结构体变量时赋初值-值未给全
	struct student stu3 = {1001, "lisi"};
	printf("num = %d, name = %s, score = %f\n", stu3.num, stu3.name, stu3.score);

	//2.1 定义结构体变量时赋初值-值未给全且给某些字段赋值
	struct student stu4 = {
		.num = 1001,
		.score = 99
	};
	printf("num = %d, name = %s, score = %f\n", stu4.num, stu4.name, stu4.score);

	//3.定义结构体时顺便定义变量
	printf("num = %d, name = %s, score = %f\n", stu5.num, stu5.name, stu5.score);

	stu6.num = 1007;
	strcpy(stu6.name, "wangwu");
	stu6.score = 70;
	printf("num = %d, name = %s, score = %f\n", stu6.num, stu6.name, stu6.score);

	return 0;
}
